//
//  HD_HSP_ExhibitListViewController.m
//  HDLiaoNingMeseum
//
//  Created by HDHaoShaoPeng on 2017/8/5.
//  Copyright © 2017年 HDNiuKuiming. All rights reserved.
//

#import "HD_HSP_ExhibitListViewController.h"
#import "HD_HSP_ListTableViewCell.h"
#import "HD_HSP_Player_ViewController.h"
#import "HD_HSP_ExhibitListViewController.h"
@interface HD_HSP_ExhibitListViewController ()
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
@property (weak, nonatomic) IBOutlet UILabel *myTitleLabel;

@end

static HDDeclare *declare;
static NSString *cellName = @"HD_HSP_ListTableViewCell";

@implementation HD_HSP_ExhibitListViewController
{
    NSArray *_dataArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    declare = [HDDeclare sharedDeclare];
    
    
    self.myTitleLabel.text = self.model.name;
    self.myTitleLabel.font = [UIFont fontWithName:@"FZQKBYSJW--GB1-0" size:18.0];
    
    NSArray *tempArr = [declare giveMeExhibitData];
    NSMutableArray *exhibits = [NSMutableArray arrayWithCapacity:200];
    for (HD_HSP_Exhibit_Model *model in tempArr) {
        if (model.unitNum.intValue == self.model.type) {
            [exhibits addObject:model];
        }
    }
    
    _dataArr = exhibits;
    
    
    [self.myTableView registerNib:[UINib nibWithNibName:cellName bundle:nil] forCellReuseIdentifier:cellName];
    
    [self.myTableView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    
    if ([segue.identifier isEqualToString:@"showDetailLine"]) {
        HD_HSP_Player_ViewController *vc = segue.destinationViewController;
        HD_HSP_Exhibit_Model *model = [[HD_HSP_Exhibit_Model alloc]init];
        model.FileNum = @"0104";
        vc.detailItem = model;
    }
}


#pragma mark - tableView delegate

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HD_HSP_ListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName forIndexPath:indexPath];
    cell.model = _dataArr[indexPath.row];
    [cell layoutSubviews];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    HD_HSP_Player_ViewController *firVC = [[UIStoryboard storyboardWithName:@"HD_HSP_Data" bundle:nil] instantiateViewControllerWithIdentifier:@"HD_HSP_Player_ViewController"];
    firVC.detailItem = _dataArr[indexPath.row];
    [self.navigationController pushViewController:firVC animated:YES];
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120.0;
}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{   //if (!indexPath.section) return UITableViewCellEditingStyleNone; // 第一组家和公司不提供左滑删除功能
    return UITableViewCellEditingStyleDelete;
}
//- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath {
//    if (editingStyle == UITableViewCellEditingStyleDelete) {
//        
//        //[self.da removeObjectAtIndex:indexPath.row];
//        [self.myTableView deleteRowsAtIndexPaths:@[indexPath]
//                                withRowAnimation:UITableViewRowAnimationAutomatic];
//        [self.myTableView reloadData];
//    }
//}

//-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return YES;
//}



#pragma mark - 点击方法

- (IBAction)backBtnClicked:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}




@end
